﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Evaluant.Uss.Xml
{
    class XPathTransformer : NLinqVisitors.NLinqExpressionVisitor
    {
        private Model.Model model;
        private bool isFirstFrom;
        //Cannot use another dictionnary, because the enumeration may not return the items 
        //in the order they were added
        private Dictionary<string, string> identifiers;
        private bool inWhere;

        public XPathTransformer(Model.Model model)
        {
            this.model = model;
            isFirstFrom = true;
            identifiers = new Dictionary<string, string>();
        }

        public override NLinq.Expressions.QueryBodyClause Visit(NLinq.Expressions.FromClause expression)
        {
            if (isFirstFrom)
            {
                isFirstFrom = false;
                identifiers.Add(expression.Identifier.Text, "Entity[Type='" + expression.Type + "'");
            }
            return expression;
        }

        public override NLinq.Expressions.QueryBodyClause Visit(NLinq.Expressions.WhereClause expression)
        {
            bool wasInWhere = inWhere;
            inWhere = true;
            var result = base.Visit(expression);
            inWhere = wasInWhere;
            return result;
        }

        public override NLinq.Expressions.Expression Visit(NLinq.Expressions.BinaryExpression item)
        {
            new System.Xml.XPath.XPathExpression
            return base.Visit(item);
        }
    }
}
